
import { cacheTools, toast } from 'nc-lightapp-front';

export default class DimissionModalAction{
    constructor(comp){
        this.comp = comp
    }
    //选择生效时间
    changeDate = async ( date )=>{
        const { dispatch } = this.comp.props;
        await dispatch({
            type: 'main/update',
            payload: {
                dateData: date
            }
        })
    }

    //离职确认
    affirmDimissionAction = async ()=>{
        const { props, action } = this.comp;
        const { main, dispatch } = props;
        let { dateData, orgvalue } = main;
        let _this = this;
        let number = props.editTable.getNumberOfRows('list');
        let billid = '';
        if(number > 0 && main.showPage === 'list'){
           billid = props.editTable.getValByKeyAndIndex('list',main.focusIndex,'pk_hi_stapply').value;
        }else if( main.showPage === 'card'){
            billid = props.form.getFormItemsValue('card','pk_hi_stapply').value;
        }
        dispatch({
            type: 'main/dismConfrim',
            payload: {
                pk_org: orgvalue.refpk,
                billid: billid,
                effectDate: dateData
            }
        }).then((res) => {
            if(res.data){
                if(res.data.warningMag){
                    toast({ color: 'warning', content: res.data.warningMag})
                }else{
                    toast({ color: 'success', content: main.json['gx6008-000052'] });
                }
                if(main.showPage === 'list'){
                    _this.pubSub.publish('queryTableData',{})
                }else{
                    let orginPks = cacheTools.get('allpks')
                    let index = orginPks.indexOf(billid)
                    props.editTable.deleteTableRowsByIndex('list', index);
                    orginPks.splice(billid, 1)
                    cacheTools.set('allpks', orginPks)
                    let n = props.cardPagination.getNextCardPaginationId({ id: billid, status: 3 });
                    if (cacheTools.get('allpks').length === 1) {
                        n = cacheTools.get('allpks')[0]
                    }
                    action.headerAction.handlePageInfoChange(props, n, 1)
                }
            }
        },(err) => {
        })
    }
}
